package com.zyy.smartcity1129.lifepay;

import android.graphics.Color;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.MutableLiveData;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.MainActivity;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.data.GpsInfo;
import com.zyy.smartcity1129.util.Http;

/**
 * @ClassName: LifePayFragment$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 7/12/2021$
 * @Version: 1.0
 */
public class LifePayFragment extends BaseFragment {
    private FrameLayout fragmentLP;
    public static BottomNavigationView bottomLP;

    @Override
    protected int layId() {
        return R.layout.f_lifepay;
    }

    @Override
    protected String title() {
        right.setVisibility(View.VISIBLE);
        right.setText("北京");
        imgRight.setVisibility(View.VISIBLE);
        imgRight.setImageResource(R.drawable.linemap);
        imgRight.setColorFilter(Color.BLACK);
        return "生活缴费";
    }

    @Override
    protected boolean back() {
        return true;
    }

    @Override
    protected Boolean bottom() {
        return null;
    }
    public static MutableLiveData<String> mutableLiveData = new MutableLiveData<>();
    @Override
    protected void init(View iv) {
        initView(iv);
        Http.base="http://124.93.196.45:10001";
        Http.token= MainActivity.mToken;
        mutableLiveData.observe(getViewLifecycleOwner(), s -> {
            title.setText(s);
        });
        imgRight.setOnClickListener(view -> {
            th(() -> {
                GpsInfo.DataBean gps = Http.getInstance().get("/prod-api/api/common/gps/location", null, GpsInfo.class, 1).getData();
                ui(() -> {
                    right.setText(gps.getCity());
                });
            });
        });
        getActivity().getSupportFragmentManager().beginTransaction().add(R.id.fragmentLP, new LPFragment()).commit();
        bottomLP.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.lpPay:
                        add(new LPFragment());
                        break;
                    case R.id.lpAccount:
                        add(new LPAccountFragment());
                        break;
                }
                return false;
            }
        });
    }

    public void add(Fragment fragment){
        getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragmentLP,fragment).commit();
    }

    private void initView(View iv) {
        fragmentLP = (FrameLayout) iv.findViewById(R.id.fragmentLP);
        bottomLP = (BottomNavigationView) iv.findViewById(R.id.bottomLP);
    }
}
